package tmt.usercenter.web.domain;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.voodoodyne.jackson.jsog.JSOGGenerator;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.CreatedDate;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;

@Getter
@Setter
@Entity
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler","fieldHandler"})
@JsonIdentityInfo(generator = JSOGGenerator.class)
public class LoginHistory extends BaseDomain implements Serializable {

    @Temporal(TemporalType.TIMESTAMP)
    private Date logoutTime;

    private String ipAddress;

    /**
     * 用户登录的客户系统。
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "originSystem_id", nullable = false)
    private ClientSystem originSystem;

    /**
     * 登录的用户。
     */
    @ManyToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY, optional = false)
    @JoinColumn(name = "user_id", nullable = false)
    private TmtUser tmtUser;

    public LoginHistory(){}

    public LoginHistory(TmtUser tmtUser, String ipAddress, ClientSystem clientSystem){
        this.tmtUser = tmtUser;
        this.ipAddress = ipAddress;
        this.originSystem = clientSystem;
    }

}
